package handlers

import (
	"github.com/gin-gonic/gin"
	"store-data/models"
)

func Add(c *gin.Context) {
	name := c.PostForm("name")
	address := c.PostForm("address")

	data := models.Store{
		Name:    name,
		Address: address,
	}
	err := models.DB.Create(&data).Error
	if err != nil {
		c.JSON(200, gin.H{
			"code": 0,
			"msg":  "添加失败",
		})
		return
	}
	c.JSON(200, gin.H{
		"code": 200,
		"msg":  "添加成功",
		"data": data,
	})
	return
}
func List(c *gin.Context) {
	var store []models.Store

	models.DB.Find(&store)

	c.JSON(200, gin.H{
		"code": 200,
		"msg":  "查找成功",
		"data": store,
	})
	return
}
